from twisted.internet import reactor, task
import os
import sys
import getopt

def watch(args):
    print '\033[H\033[2J'
    os.system(' '.join(args))

if __name__ == '__main__':
    delay = 1.0
    opts, args = getopt.getopt(sys.argv[1:], "hn:")
    for opt, arg in opts:
        if opt in ('-h'):
            print 'Usage:', sys.argv[0], ' [-h] [-n interval] <command>'
            sys.exit(0)
        if opt in ('-n'):
            delay = float(arg)
    t = task.LoopingCall(watch, args)
    t.start(delay)
    reactor.run()
